
* DID ESTIMATES OF SHARES OF INMOVERS

cd "$mypathRR/Results/Resident/results_01-07"


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* GENERATE THE TREATMENT (AND CONTROL) GROUP 

cap rm "$mypathRR/Results/appendixtables/B5.1_appendixtable.xls"
cap rm "$mypathRR/Results/appendixtables/B5.1_appendixtable.txt"

local b " 60 60 "
local t " 80 95 "
local n : word count `b'

forvalues i = 1/`n' {
local x : word `i' of `b'
local y : word `i' of `t'
cap drop treat_i
gen treat_i=.
replace treat_i=0 if ctrl_ir_`x'_`y'==1
replace treat_i=1 if taxinc_thre2==1
label var treat_i "Income tax treatment"


preserve
sort persid year

drop if year>2007

collapse (count) Inmovers=persid (mean) avgtt=avgt_stek_taxable (mean) avgtg=avgt_stek_gross (mean) mtr=mtr_total (mean) residents , by(year treat_i)
gen weight=Inmovers

xtset treat_i year
tsfill, full
replace Inmovers=0 if Inmovers==.


replace Inmovers=Inmovers/residents*100
label var Inmovers "Share of taxpayers"
label var avgtt "Average tax rate on taxable income"
label var avgtg "Average tax rate on gross income"
label var mtr "Marginal tax rate on taxable income"
label var treat_i "Treatment"
label var year "Year"

gen Period=(year>=2006)
gen DiD=treat_i*Period

* 2SLS
gen lnnet_avgtt = ln(1-avgtt)
label var lnnet_avgtt "$\eta$"
 
ivreg2 Inmovers treat_i  ib2005.year (lnnet_avgtt = DiD) , ffirst redundant(DiD)  robust
weakivtest
		
// REGRESSION TABLE FOR APPENDIX
	outreg2 using "$mypathRR/Results/appendixtables/B5.1_appendixtable.xls", excel label  e(F) dec(3) append ///
	sortvar(DiD lnnet_avgtt treat_i i.year  ) ctitle(" ", "Stock Elasticities", "`x'--`y'\%", "2SLS")


restore
drop treat_i


}






* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* 2 TREATMENTS

local b " 60 60"
local t " 80 95"
local n : word count `b'

forvalues i = 1/`n' {
local x : word `i' of `b'
local y : word `i' of `t'
cap drop treat_i
gen treat_i=.
replace treat_i=0 if ctrl_ir_`x'_`y'==1
replace treat_i=1 if taxinc_thre2==1
label var treat_i "Income tax treatment"

preserve
sort persid year

drop if year>2010

collapse (count) Inmovers=persid (mean) avgtt=avgt_stek_taxable (mean) avgtg=avgt_stek_gross (mean) mtr=mtr_total (mean) residents , by(year treat_i)
gen weight=Inmovers

xtset treat_i year
tsfill, full
replace Inmovers=0 if Inmovers==.

replace Inmovers=Inmovers/residents*100
label var Inmovers "Share of taxpayers"
label var avgtt "Average tax rate on taxable income"
label var avgtg "Average tax rate on gross income"
label var mtr "Marginal tax rate on taxable income"
label var treat_i "Treatment"
label var year "Year"

gen Period1=0
replace Period1=1 if year>=2006&year<2008
gen DiD1=treat_i*Period1

gen Period2=0
replace Period2=1 if year>=2008
gen DiD2=treat_i*Period2


* 2SLS
gen lnnet_avgtt = ln(1-avgtt)
label var lnnet_avgtt "$\eta^F$"
 
ivreg2 Inmovers treat_i  ib2005.year (lnnet_avgtt = DiD1 DiD2), ffirst redundant(DiD1 DiD2) robust
weakivtest

	outreg2 using "$mypathRR/Results/appendixtables/B5.1_appendixtable.xls", excel label  e(F) dec(3) append ///
	sortvar(DiD lnnet_avgtt treat_i i.year  ) ctitle(" ", " ", "`x'--`y'\%", "2SLS") 


restore
drop treat_i

}





